package contest.co6150;

import java.util.Stack;

public class Solution {
    public String smallestNumber(String pattern) {
        char c='1';
        Stack<Character> stack=new Stack<>();
        stack.push(c);
        StringBuilder stringBuilder=new StringBuilder();
        for (int i = 0; i < pattern.length(); i++) {
            if (pattern.charAt(i)=='I'){

                while (!stack.empty()){
                    stringBuilder.append(stack.pop());
                }
            }
            c++;
            stack.push(c);
        }
        while (!stack.empty()){
            stringBuilder.append(stack.pop());
        }
        return stringBuilder.toString();
    }
}
